package cn.hinglo.activemq.controller;

import cn.hinglo.activemq.entity.LogInfo;
import cn.hinglo.common.constant.QueueConstant;
import cn.hinglo.common.entity.Result;
import cn.hinglo.common.utils.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * @author HingLo
 * @createTime: 2018/9/17 15:54
 * @description: 日志生产者
 */
@RestController
@RequestMapping("log")
@Slf4j
public class LogController {

    private final JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    public LogController(JmsMessagingTemplate jmsMessagingTemplate) {
        this.jmsMessagingTemplate = jmsMessagingTemplate;
    }

    /**
     * 消息队列测试
     *
     * @return 返回消息发送结果
     */
    @PostMapping("/send")
    public Result send() {
        LogInfo logInfo = new LogInfo();
        logInfo.setClazz("日志记录的类名称").setDesc("这是日志记录测试").setIp("请求的Ip").setNum(1).setUrl("请求的url").setUserId("操作人").setTime(new Date())
                .setType(1);
        jmsMessagingTemplate.convertAndSend(QueueConstant.LOG_QUEUE, logInfo);
        log.info("日志记录消息生产成功");
        return ResultUtils.success();
    }
}
